package admin.code.generator.util;

import java.io.File;

/**
 *
 *@author Jack
 *2016年3月5日下午11:59:25
 */
public class ClassPathMaker {
	private String projectName;
	private String basePackagePath;
	private String diskPath;

	public ClassPathMaker(String diskPath, String projectName, String basePackage) {
		super();
		diskPath = diskPath.endsWith(File.separator) ? diskPath : diskPath + File.separator;
		this.diskPath = diskPath;
		this.projectName = projectName;
		this.basePackagePath = convertPath(basePackage);
	}

	private String convertPath(String basePackage) {
		if(StringUtil.isNotBlank(basePackage))
			return basePackage.replace(".", File.separator);
		return "";
	}

	public String buildClassPath(String moduleName, String subPackageName) {
		if (StringUtil.isNotBlank(projectName)) {
			return new StringBuilder(diskPath).append(projectName)//
					.append(File.separator).append(projectName + "-" + moduleName)//
					.append(File.separator).append(basePackagePath + File.separator + subPackageName + File.separator)//
					.toString();
		} else {
			// 路径中不包含项目名称
			return new StringBuilder(diskPath).append(basePackagePath + File.separator + subPackageName + File.separator)//
					.toString();
		}
	}

	public String buildDomainPath() {
		return buildClassPath("model", "model");
	}

	public String buildControllerPath() {
		return buildClassPath("web", "controller");
	}

	public String buildServicePath() {
		return buildClassPath("service", "service");
	}

	public String buildServiceImplPath() {
		return buildClassPath("service", "service" + File.separator + "impl");
	}

	public String buildDaoPath() {
		return buildClassPath("dao", "dao");
	}

	public String buildDaoImplPath() {
		return buildClassPath("dao", "dao" + File.separator + "impl");
	}
}
